<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="quik.article.ArticleProc"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashMap"%>
<%@page import="comm.util.RequestManager"%>
<%@page import="comm.util.CommUtil"%>
<%@page import="quik.group.GroupProc"%>
<%@page import="comm.util.QuikHashMap"%>
<%
	if(session.getAttribute("SESSION_MEMBER_SEQ")!=null && session.getAttribute("SESSION_MEMBER_GROUPSEQ")!=null){
		ArticleProc article = new ArticleProc();
		ArrayList lt = null;
		
		QuikHashMap rhm = RequestManager.getRequest(request);
		if(rhm.get("PAGE_NUM")!=null && rhm.get("PAGE_SIZE")!=null){
			lt = article.getArticleList(Integer.parseInt(rhm.get("PAGE_NUM").toString()),
												Integer.parseInt(rhm.get("PAGE_SIZE").toString()),
												request);
		}else{
			lt = article.getArticleList(1,Integer.parseInt(CommUtil.PAGE_SIZE),request);
		}
		GroupProc group = new GroupProc();
		ArrayList groupList = null;
		groupList = group.getMembersGroupList(session.getAttribute("SESSION_MEMBER_SEQ").toString());
		int cntList = 0;
		String firstInnerGroupSeq = "";
		if(groupList!=null)
			cntList = groupList.size();
%> 


<title>Quik :: <%=CommUtil.NVL(session.getAttribute("SESSION_MEMBER_GROUPNAME").toString())%> - 마이페이지</title>

<%@include file="./headerMenu.jsp" %>
<%@include file="./sideBar.jsp" %>
<div id="contents">
	<!-- 프로필 부분 -->
	<%if(rhm.get("MENU")!=null && rhm.get("MENU").equals("profile")){ %>
		<jsp:include page="./profile/index.jsp"></jsp:include>
	<!-- 동료 부분 -->
	<%}else if(rhm.get("MENU")!=null && rhm.get("MENU").equals("coworker")){ %>
		<jsp:include page="./coworker/index.jsp"></jsp:include>
	
	<!-- 그룹 부분 -->
	<%}else if(rhm.get("MENU")!=null && rhm.get("MENU").equals("group")){ %>
		<jsp:include page="./group/index.jsp"></jsp:include>
	
	<!-- 자료 부분 -->
	<%}else if(rhm.get("MENU")!=null && rhm.get("MENU").equals("data")){ %>
		<jsp:include page="./data/index.jsp"></jsp:include>
	
	<!-- 검색 결과 부분 -->
	<%}else if(rhm.get("MENU")!=null && rhm.get("MENU").equals("search")){ %>
		<jsp:include page="./search/index.jsp"></jsp:include>
	
	<!-- 메인 -->
	<%}else{ %>
	
	<!-- 메세지 입력창 -->
	<div id="content-top"></div>
		<div id="lista" class="box">
			<div id="content-text">
				<form method="post" action="./jsp/mypage/mypage_write_proc.jsp" enctype="multipart/form-data" class="message">
					<div>
						<input type="hidden" name="url" value="../../?content=mypage"/>
						<p><textarea name="article_content" rows="3"></textarea></p>
						
						받는이 : <select name="innergroup_seq">
							<option value="">동료들에게</option>
							<%
							for(int i = 0;i<cntList;i++){
								QuikHashMap hm = new QuikHashMap();
								hm = (QuikHashMap)groupList.get(i);
								if(i==0)
									firstInnerGroupSeq = hm.get("INNERGROUP_SEQ").toString();
							%>
							<option value="<%=hm.get("INNERGROUP_SEQ") %>"><%=hm.get("GROUP_NAME")%></option>
							<%}%>
						</select>				
						<input type="submit" value="보내기" style="width:310px;"/>
						<!-- 
						<input type="button" value="파일첨부(클릭시 레이어 뜨게 나중에)"/>
						 -->
					</div>
					<div><input type="button" value="자료 첨부하기" onclick="javascript:callAddDataForm(); " /></div>
					<div id="addData" style="display: none;">
						<div>파일 첨부 : <input type="file" name="file"/></div>
						<div>링크 : <input type="text" name="comment" value="http://"/></div>
					</div>
				</form>
			</div>
		</div>
	<div id="content-bottom"></div>
	<!-- 글 출력 -->
	<%
	String curGroup = firstInnerGroupSeq;
	if(request.getParameter("group")!=null && request.getParameter("group").toString().length()>0){
		curGroup = request.getParameter("group").toString();
	}
	%>
	<div>
		<%
		if(request.getParameter("group")!=null && request.getParameter("group").toString().length()>0){
			
				lt = null;
		HashMap secHm = RequestManager.getRequest(request);
		if(secHm.get("PAGE_NUM")!=null && secHm.get("PAGE_SIZE")!=null){
			lt = group.getMembersGroupArticleList(curGroup,session.getAttribute("SESSION_MEMBER_GROUPSEQ").toString(),
												Integer.parseInt(secHm.get("PAGE_SIZE").toString()),
												Integer.parseInt(secHm.get("PAGE_NUM").toString())
												);
		}else{
			lt = group.getMembersGroupArticleList(curGroup,session.getAttribute("SESSION_MEMBER_GROUPSEQ").toString(),15,1);
		}
		cntList = 0;
		if(lt!=null)
			cntList = lt.size();
		
		}
	%>
		
		<%if(lt!=null&&lt.size()>0){
			for(int i = 0 ; i < lt.size() ; i++){
				QuikHashMap hm = (QuikHashMap)lt.get(i);
		%>
		<div id="content-top"></div>
		<div id="lista" class="box">
			<div id="content-text">
				<div class="img"><a href="<%=request.getContextPath()%>/user/<%=hm.get("MEMBER_SEQ")%>"><img src="./data/userImage/<%=hm.get("MEMBER_SEQ")%>/<%=hm.get("MEMBER_IMG")%>" width="<%=CommUtil.IMG_WIDTH %>" height="<%=CommUtil.IMG_WIDTH %>"/></a></div>
				<div class="nickname"><a href="<%=request.getContextPath()%>/user/<%=hm.get("MEMBER_SEQ")%>"><%=hm.get("MEMBER_NICK") %></a></div>
				<div class="body"><%=CommUtil.addLinkToUrlPattern(CommUtil.htmlFiltering(hm.get("ARTICLE_CONTENT").toString()))%></div>
				<div class="fileArea">
					<%if(hm.get("FILE")!=null){ %>
						<%if(hm.get("DATA_TYPE").toString().equals("0")){//이미지  파일 %>
						<div><img src="./data/groupData/<%=session.getAttribute("SESSION_MEMBER_GROUPSEQ")%>/<%=hm.get("FILE")%>"/></div>
						<div><a href="./data/groupData/<%=session.getAttribute("SESSION_MEMBER_GROUPSEQ")%>/<%=hm.get("FILE")%>" target="_blank"><%=hm.get("ORIGIN_FILE")%></a></div>
						<%}else if(hm.get("DATA_TYPE").toString().equals("1")){ //이미지외의 파일들%>
						<div>DATA</div>
						<div><a href="./data/groupData/<%=session.getAttribute("SESSION_MEMBER_GROUPSEQ")%>/<%=hm.get("FILE")%>" target="_blank"><%=hm.get("ORIGIN_FILE")%></a></div>
						<%} %>
					<%}else if(hm.get("COMMENT")!=null){//링크정보 %>
						<div><a href="<%=hm.get("COMMENT")%>" target="_blank"><%=hm.get("COMMENT") %></a></div>
					<%} %>
				</div>
				<div class="date"><%=hm.get("ARTICLE_REGDATE") %></div>
			</div>
		</div>
		<div id="content-bottom"></div>
		<%}
		}else{
		%>
			<div>
				<p>등록된 글이 없습니다.</p>
			</div>
		<%} %>
		
	</div>
	
	<!-- 페이지 네비게이션 -->
	<div>
		<div>
			<%if(rhm.get("PAGE_NUM")!=null && rhm.get("PAGE_SIZE")!=null && Integer.parseInt(rhm.get("PAGE_NUM").toString()) > 1){ %>
				<a href="./?content=mypage&page_num=<%=Integer.parseInt(rhm.get("PAGE_NUM").toString())-1%>&page_size=<%=CommUtil.PAGE_SIZE%>">이전페이지</a>
			<%}else{ %>
				<a title="첫번째페이지입니다.">이전페이지</a>
			<%} %>
		</div>
		<div>
			<%if(rhm.get("PAGE_NUM")!=null  && rhm.get("PAGE_SIZE")!=null && lt.size() < Integer.parseInt(rhm.get("PAGE_SIZE").toString())){ %>
				<a title="마지막페이지입니다.">다음페이지</a>
			<%}else if(rhm.get("PAGE_NUM")!=null && rhm.get("PAGE_SIZE")!=null){ %>
				<a href="./?content=mypage&page_num=<%=Integer.parseInt(rhm.get("PAGE_NUM").toString())+1%>&page_size=<%=CommUtil.PAGE_SIZE%>">다음페이지</a>
			<%}else{ %>
				<a href="./?content=mypage&page_num=2&page_size=<%=CommUtil.PAGE_SIZE%>">다음페이지</a>
			<%} %>
		</div>
	</div>
	<%} %>
	
	
</div>
<%}else if(session.getAttribute("SESSION_MEMBER_SEQ")!=null && session.getAttribute("SESSION_MEMBER_GROUPSEQ")==null){%>
	<div>가입된 그룹(회사)이 없습니다. 관리자에게 문의하세요. 01055546515</div>
<%}else{%>
<script>
	location.href="./";
</script>
<%}%>
